package cn.ccccltd.waf.id_generator.web.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.ccccltd.waf.id_generator.config.model.ResultData;
import cn.ccccltd.waf.id_generator.config.sql.param.QueryParams;
import cn.ccccltd.waf.id_generator.web.user.service.UserService;
import cn.ccccltd.waf.id_generator.web.user.vo.User;

@RestController
@RequestMapping("/user")
public class UserController {

	@Autowired
	private UserService userService;
	
	/**
	 * 功能: 用户插入<br>
	 * 作者: yangjingjiang <br>
	 * 创建日期:2018年4月2日 <br>
	 * 修改者: mender <br>
	 * 修改日期: modifydate <br>
	 * @param user
	 * @return
	 */
	@PostMapping
	public ResultData insert(@RequestBody User user) {
		
		return userService.insert(user);

	}
	
	@DeleteMapping("/{id}")
	public ResultData delete(@PathVariable String id) {
		
		return userService.delete(new User(id));
		
	}

	@PutMapping
	public ResultData update(@RequestBody User user) {
		
		return userService.update(user);
	
	}
	
	@GetMapping("/{id}")
	public ResultData get(@PathVariable String id) {
		
		return userService.get(new User(id));
		
	}

	@PostMapping("/page")
	public ResultData getByPage(@RequestBody QueryParams queryParams) {
		
		ResultData resultData = userService.getByPage(queryParams);
		
		return resultData;
	}
	
}
